/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"9DAAC1E1-FCBC-48E0-AD06-791672BB1104"}
 */
var fFormLlama = 'recepciones_carga_cab';

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"F4AD981E-FB71-4574-8778-1D9B744806F0"}
 */
function onDataChangeRemito(oldValue, newValue, event) {
	var query 	= 'select rem_cabecera_id from rem_cabecera where cliente_id = ? and nro_remito = ? and userv_id = ?'
	var args 	= new Array(forms[fFormLlama].cliente_id, remito, globals.gUservID)
	var ds 		= databaseManager.getDataSetByQuery('infocom',query,args,1)
	
	if (ds.getMaxRowIndex() == 0)
	{
		globals.DIALOGS.showInfoDialog('Error','El remito no existe para ese cliente','OK')  // 23/01/2014
		return false
	}
	onRecordSelection()
	return true
}

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"F29EEF32-B2DA-4E18-A64F-3E9AE87C1A60"}
 */
function onDataChangeCantidad(oldValue, newValue, event) {
	if (newValue > recep_detalle_to_rem_detalle_ind.cantidad)
	{
		globals.DIALOGS.showInfoDialog('Error','La cantidad es mayor a la del remito','OK') // 23/01/2014
		return false
	}
	cantidad_alter = newValue
	return true
}

/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"464CAD2C-D180-4778-A47A-51DB47542B2E"}
 */
function onDataChangeDetalle(oldValue, newValue, event) {
	cantidad 		= recep_detalle_to_rem_detalle_ind.cantidad_pendiente_fac
	producto_id 	= recep_detalle_to_rem_detalle_ind.producto_id
	precio_unitario	= recep_detalle_to_rem_detalle_ind.precio_unitario
	return true
}

/**
 * @properties={typeid:24,uuid:"83D2A857-458A-443F-8731-58467EDE0A6A"}
 */
function onRecordSelection() {
	if (remito != null)
	{
		var query = 'SELECT texto + " - " + cantidad_pendiente_fac, rem_detalle_id FROM rem_detalle where rem_cabecera_id = ?'
		var args = [recep_detalle_to_rem_detalle_ind.rem_cabecera_id]
		var ds = databaseManager.getDataSetByQuery('infocom',query,args,-1)
		
		application.setValueListItems('recepciones_remito_detalle',ds)	
	}
}
